package com.sebastian.studies.ch6;

import java.util.Scanner;

public class Excercise_6_3 {

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);
		System.out.println("Enter some numbers (eleven): ");
		int[] myArray = new int[11];

		for (int i = 0; i < myArray.length; i++) {
			myArray[i] = input.nextInt();
		}

		for (int i = 0; i < myArray.length; i++) {
			System.out.print(myArray[i] + " ");
		}

		System.out.println("\nThe average is: " + checkingAverage(myArray) 
				+ "\nTotal # of numbers below average : " + checkingHowManyNumbersAreBelowAverage(myArray)
				);
		input.close();
	}

	private static double checkingAverage(int[] array) {
		double przez = array.length;
		double sum = 0;
		for(int i = 0; i < array.length; i++) {
			sum +=array[i];
		}
		double average = sum/przez;
		return average;
	}

	private static int checkingHowManyNumbersAreBelowAverage(int[] array) {
		double average = checkingAverage(array);
		int count = 0;
		for(int i = 0; i < array.length; i++) {
			if(average > array[i]) {
				count++;
			}
		}
		return count;
	}

}
